home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 741 / rkrm_lib1 / rkrm_lib1.lha / GadTools / gadtoolsmenu.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  6KB  |  186 lines

  1. ;/*  gadtoolsmenu.c - Compiled with SAS C v5.10b
  2. lc -b1 -cfistq -v -y -j73 gadtoolsmenu
  3. blink FROM LIB:c.o gadtoolsmenu.o TO gadtoolsmenu LIB LIB:lc.lib LIB:amiga.lib
  4. quit
  5. */
  6.  
  7. /*
  8. Copyright (c) 1992 Commodore-Amiga, Inc.
  9.  
  10. This example is provided in electronic form by Commodore-Amiga, Inc. for
  11. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  12. published by Addison-Wesley (ISBN 0-201-56774-1).
  13.  
  14. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  15. information on the correct usage of the techniques and operating system
  16. functions presented in these examples.  The source and executable code
  17. of these examples may only be distributed in free electronic form, via
  18. bulletin board or as part of a fully non-commercial and freely
  19. redistributable diskette.  Both the source and executable code (including
  20. comments) must be included, without modification, in any copy.  This
  21. example may not be published in printed form or distributed with any
  22. commercial product.  However, the programming techniques and support
  23. routines set forth in these examples may be used in the development
  24. of original executable software products for Commodore Amiga computers.
  25.  
  26. All other rights reserved.
  27.  
  28. This example is provided "as-is" and is subject to change; no
  29. warranties are made.  All use is at your own risk. No liability or
  30. responsibility is assumed.
  31. */
  32.  
  33. /* gadtoolsmenu.c
  34. ** Example showing the basic usage of the menu system with a window.
  35. ** Menu layout is done with GadTools, as is recommended for applications.
  36. **
  37. */
  38.  
  39. #define INTUI_V36_NAMES_ONLY
  40.  
  41. #include <exec/types.h>
  42. #include <intuition/intuition.h>
  43. #include <intuition/intuitionbase.h>
  44. #include <libraries/gadtools.h>
  45.  
  46. #include <clib/exec_protos.h>
  47. #include <clib/gadtools_protos.h>
  48. #include <clib/intuition_protos.h>
  49.  
  50. #include <stdio.h>
  51.  
  52. #ifdef LATTICE
  53. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  54. int chkabort(void) { return(0); }  /* really */
  55. #endif
  56.  
  57. struct Library *GadToolsBase;
  58. struct IntuitionBase *IntuitionBase;
  59.  
  60. struct NewMenu mynewmenu[] =
  61.     {
  62.         { NM_TITLE, "Project",    0 , 0, 0, 0,},
  63.         {  NM_ITEM, "Open...",   "O", 0, 0, 0,},
  64.         {  NM_ITEM, "Save",      "S", 0, 0, 0,},
  65.         {  NM_ITEM, NM_BARLABEL,  0 , 0, 0, 0,},
  66.         {  NM_ITEM, "Print",      0 , 0, 0, 0,},
  67.         {   NM_SUB, "Draft",      0 , 0, 0, 0,},
  68.         {   NM_SUB, "NLQ",        0 , 0, 0, 0,},
  69.         {  NM_ITEM, NM_BARLABEL,  0 , 0, 0, 0,},
  70.         {  NM_ITEM, "Quit...",   "Q", 0, 0, 0,},
  71.  
  72.         { NM_TITLE, "Edit",       0 , 0, 0, 0,},
  73.         {  NM_ITEM, "Cut",       "X", 0, 0, 0,},
  74.         {  NM_ITEM, "Copy",      "C", 0, 0, 0,},
  75.         {  NM_ITEM, "Paste",     "V", 0, 0, 0,},
  76.         {  NM_ITEM, NM_BARLABEL,  0 , 0, 0, 0,},
  77.         {  NM_ITEM, "Undo",      "Z", 0, 0, 0,},
  78.  
  79.         {   NM_END, NULL,         0 , 0, 0, 0,},
  80.     };
  81.  
  82.  
  83. /*
  84. ** Watch the menus and wait for the user to select the close gadget
  85. ** or quit from the menus.
  86. */
  87. VOID handle_window_events(struct Window *win, struct Menu *menuStrip)
  88. {
  89. struct IntuiMessage *msg;
  90. SHORT done;
  91. UWORD menuNumber;
  92. UWORD menuNum;
  93. UWORD itemNum;
  94. UWORD subNum;
  95. struct MenuItem *item;
  96.  
  97. done = FALSE;
  98. while (FALSE == done)
  99.     {
  100.     /* we only have one signal bit, so we do not have to check which
  101.     ** bit broke the Wait().
  102.     */
  103.     Wait(1L << win->UserPort->mp_SigBit);
  104.  
  105.     while ( (FALSE == done) &&
  106.             (NULL != (msg = (struct IntuiMessage *)GetMsg(win->UserPort))))
  107.         {
  108.         switch (msg->Class)
  109.             {
  110.             case IDCMP_CLOSEWINDOW:
  111.                 done = TRUE;
  112.                 break;
  113.             case IDCMP_MENUPICK:
  114.                 menuNumber = msg->Code;
  115.                 while ((menuNumber != MENUNULL) && (!done))
  116.                     {
  117.                     item = ItemAddress(menuStrip, menuNumber);
  118.  
  119.                     /* process the item here! */
  120.                     menuNum = MENUNUM(menuNumber);
  121.                     itemNum = ITEMNUM(menuNumber);
  122.                     subNum  = SUBNUM(menuNumber);
  123.  
  124.                     /* stop if quit is selected. */
  125.                     if ((menuNum == 0) && (itemNum == 5))
  126.                         done = TRUE;
  127.  
  128.                     menuNumber = item->NextSelect;
  129.                     }
  130.                 break;
  131.             }
  132.         ReplyMsg((struct Message *)msg);
  133.         }
  134.     }
  135. }
  136.  
  137.  
  138. /*
  139. ** Open all of the required libraries and set-up the menus.
  140. */
  141. VOID main(int argc, char *argv[])
  142. {
  143. struct Window *win;
  144. APTR *my_VisualInfo;
  145. struct Menu *menuStrip;
  146.  
  147. /* Open the Intuition Library */
  148. IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37);
  149. if (IntuitionBase != NULL)
  150.     {
  151.     /* Open the gadtools Library */
  152.     GadToolsBase = OpenLibrary("gadtools.library", 37);
  153.     if (GadToolsBase != NULL)
  154.         {
  155.         if (NULL != (win = OpenWindowTags(NULL,
  156.                             WA_Width,  400,       WA_Activate,    TRUE,
  157.                             WA_Height, 100,       WA_CloseGadget, TRUE,
  158.                             WA_Title,  "Menu Test Window",
  159.                             WA_IDCMP,  IDCMP_CLOSEWINDOW | IDCMP_MENUPICK,
  160.                             TAG_END)))
  161.             {
  162.             if (NULL != (my_VisualInfo = GetVisualInfo(win->WScreen, TAG_END)))
  163.                 {
  164.                 if (NULL != (menuStrip = CreateMenus(mynewmenu, TAG_END)))
  165.                     {
  166.                     if (LayoutMenus(menuStrip, my_VisualInfo, TAG_END))
  167.                         {
  168.                         if (SetMenuStrip(win, menuStrip))
  169.                             {
  170.                             handle_window_events(win,menuStrip);
  171.  
  172.                             ClearMenuStrip(win);
  173.                             }
  174.                         FreeMenus(menuStrip);
  175.                         }
  176.                     }
  177.                 FreeVisualInfo(my_VisualInfo);
  178.                 }
  179.             CloseWindow(win);
  180.             }
  181.         CloseLibrary((struct Library *)GadToolsBase);
  182.         }
  183.     CloseLibrary((struct Library *)IntuitionBase);
  184.     }
  185. }
  186.